package com.example.demo.leetcode.simple;


/**
 * 递归函数来计算斐波那契数列（Fibonacci sequence）
 *
 * 用文字来说，就是前两个数都是1，从第三个数开始，每个数都是前两个数之和
 *
 * @author luowj12
 * @since 2021/3/22 14:48
 */
public class FibonacciMian {


    public static void main(String args[]) {

        int num =  getValue(4);
        System.out.println(num);
    }

    private static int a;

    public static int getValue(int index) {
        if (index == 1) {
            a = 1;
        }
        if (index == 2) {
            a = 1;
        }
        if (index >= 3) {
            a = getValue(index - 1) + getValue(index - 2);
        }
        return a;
    }

    public static int getValueAdd(int index) {
        if (index == 1) {
            a = 1;
        }
        if (index == 2) {
            a = 1;
        }
        if (index >= 3) {
            a = getValueAdd(index - 1) + getValueAdd(index - 2);
        }
        return a;
    }

}
